
export default {
	install(Vue){
      //去掉字符串空格
		  
	 	//  Vue.prototype.Trim=(str,is_global)=>{
		// 	var  result;
		//     result = str.replace(/(^\s+)|(\s+$)/g,"");
		//     if(is_global.toLowerCase()=="g"){
		//        result = result.replace(/\s/g,"");
		//      }
		//      return result;
		// }

		Vue.prototype.getDateDiff = (obj,type) => { 
			if(obj){
				var dateTimeStamp =null;
				if(type=='getTime'){
					dateTimeStamp=obj;
				}else{
					dateTimeStamp= Date.parse(obj.replace(/-/g,'/'));
				} 
				var result = ''
				var second = 1000;
				var minute = 1000 * 60;
				var hour = minute * 60;
				var day = hour * 24;
				var halfamonth = day * 15;
				var month = day * 30;
				var now = new Date().getTime();
				var diffValue = now - dateTimeStamp;
				if (diffValue < 0) {
					return "刚刚";
				}
				var secondC = diffValue / second;
				var monthC = diffValue / month;
				var weekC = diffValue / (7 * day);
				var dayC = diffValue / day;
				var hourC = diffValue / hour;
				var minC = diffValue / minute;
				if (dayC >= 1) {
					
					if(type=='getTime'){
						var date = new Date(obj);//时间戳为10位需*1000，时间戳为13位的话不需乘1000
						var Y = date.getFullYear() + '-';
						var M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
						var D = date.getDate() + 1 < 10 ? '0'+ date.getDate() + ' ' : date.getDate() + ' ';
						result = Y+M+D;
					}else{
						result = obj;
					}
				} else if (hourC >= 1) {
					result = "" + parseInt(hourC) + "小时前";
				} else if (minC >= 1) {
					result = "" + parseInt(minC) + "分钟前";
				} else if (secondC >= 1) {
					result = "" + parseInt(secondC) + "秒前";
				} else {
					result = "刚刚";
				} 
				return result;
			}else{
				return ''
			}
            
		}

	}
}